<html>

<?php

ini_set("memory_limit","256M");
ini_set("max_execution_time","600");

//Automagically load Classes where needed from ../includes/ClassName.class.php
function __autoload($class_name) {
	require_once '../includes/' . $class_name . '.class.php';
}

function DatabaseGetMax() {

	$db_time_start = microtime(true);
	$db = new Database;
	$db_time_query = microtime(true);
	$db_spells = $db->Query("SELECT SQL_NO_CACHE MAX(id) FROM spells_new");
	$db_time_end = microtime(true);
	
	$db_time_total_overhead = $db_time_query - $db_time_start;
	$db_time_total_query = $db_time_end - $db_time_query;
	$db_time_total_mysql = $db->GetBenchmarks();
	$db_time_total = $db_time_end - $db_time_start;
	echo "Result: " . $db_spells[1]["MAX(id)"] . "<br>\n";
	echo "Class Time: " . $db_time_total_overhead . " seconds<br>\n";
	echo "Query Time: " . $db_time_total_query . " seconds (MySQL Time: " . $db_time_total_mysql[Query][result][total] . " seconds)<br>\n";
	echo "Total Time: " . $db_time_total . " seconds<br>\n";

}

function DatabaseLoad() {

	$db_time_start = microtime(true);
	$db = new Database;
	$db_time_query = microtime(true);
	$db_spells = $db->Query("SELECT SQL_NO_CACHE * FROM spells_new");
	$db_time_end = microtime(true);
	
	$db_time_total_overhead = $db_time_query - $db_time_start;
	$db_time_total_query = $db_time_end - $db_time_query;
	$db_time_total_mysql = $db->GetBenchmarks();
	$db_time_total = $db_time_end - $db_time_start;
	echo "Spells Loaded: " . count($db_spells) . "<br>\n";
	echo "Class Time: " . $db_time_total_overhead . " seconds<br>\n";
	echo "Query Time: " . $db_time_total_query . " seconds (MySQL Time: " . $db_time_total_mysql[Query][result][total] . " seconds)<br>\n";
	echo "Total Time: " . $db_time_total . " seconds<br>\n";

}

function FileGetMax() {

	$file_dir = "";	// needs / at the end if anything other than the current directory
	$file_name = "spells_us.txt";
	
	$file_time_start = microtime(true);
	if (file_exists($file_dir . $file_name) && is_readable($file_dir . $file_name)) {

		$file_time_load = microtime(true);
		$Lines = file($file_dir . $file_name);
		
		$file_time_parse = microtime(true);
		foreach($Lines as $key => $value) {
			$Data[$key] = explode("^", $value);
		}

		$file_time_end = microtime(true);

	} else {
		echo "Unable to read: " . $file_dir . $file_name . "<br>\n";
	}
	
	if (!$file_time_end)
		$file_time_end = microtime(true);
	
	$file_time_total_open = $file_time_load - $file_time_start;
	$file_time_total_load = $file_time_parse - $file_time_load;
	$file_time_total_parse = $file_time_end - $file_time_parse;
	$file_time_total = $file_time_end - $file_time_start;
	echo "Result: " . $Data[count($Data)-1][0] . "<br>\n";
	echo "Open Time: " . $file_time_total_open . " seconds<br>\n";
	echo "Load Time: " . $file_time_total_load . " seconds<br>\n";
	echo "Parse Time: " . $file_time_total_parse . " seconds<br>\n";
	echo "Total Time: " . $file_time_total . " seconds<br>\n";


}

function FileLoad() {

	$file_dir = "";	// needs / at the end if anything other than the current directory
	$file_name = "spells_us.txt";
	
	$file_time_start = microtime(true);
	if (file_exists($file_dir . $file_name) && is_readable($file_dir . $file_name)) {

		$file_time_load = microtime(true);
		$Lines = file($file_dir . $file_name);
		
		$file_time_parse = microtime(true);
		foreach($Lines as $key => $value) {
			$Data[$key] = explode("^", $value);
		}

		$file_time_end = microtime(true);

	} else {
		echo "Unable to read: " . $file_dir . $file_name . "<br>\n";
	}
	
	if (!$file_time_end)
		$file_time_end = microtime(true);
	
	$file_time_total_open = $file_time_load - $file_time_start;
	$file_time_total_load = $file_time_parse - $file_time_load;
	$file_time_total_parse = $file_time_end - $file_time_parse;
	$file_time_total = $file_time_end - $file_time_start;
	echo "Spells Loaded: " . count($Lines) . "<br>\n";
	echo "Open Time: " . $file_time_total_open . " seconds<br>\n";
	echo "Load Time: " . $file_time_total_load . " seconds<br>\n";
	echo "Parse Time: " . $file_time_total_parse . " seconds<br>\n";
	echo "Total Time: " . $file_time_total . " seconds<br>\n";
	
}

echo "<b>DatabaseGetMax()</b><br>\n";
DatabaseGetMax();
echo "<br>\n";
echo "<b>DatabaseLoad()</b><br>\n";
DatabaseLoad();
echo "<br>\n";
echo "<b>FileGetMax()</b><br>\n";
FileGetMax();
echo "<br>\n";
echo "<b>FileLoad()</b><br>\n";
FileLoad();

?>

</html>